package com.wbsxch.blog.result;

import com.wbsxch.blog.enums.ErrorCode;
import lombok.Data;

@Data
public class ResultData {

    //返回编码
    private Integer code;

    //提示信息
    private String msg;

    //返回数据
    private Object data;

    //记录总数
    private Long count;

    public ResultData() {
    }

    public ResultData(Integer code, String msg, Object data, Long count) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.count = count;
    }

    //请求成功
    public static ResultData ok(){
        return new ResultData(ErrorCode.SERVER_OK.getCode(),ErrorCode.SERVER_OK.getMessage(),null,null);
    }

    //自定义请求成功
    public static ResultData ok(ErrorCode errorCode){
        return new ResultData(errorCode.getCode(),errorCode.getMessage(),null,null);
    }

    //自定义请求
    public static ResultData ok(Integer code,String message){
        return new ResultData(code,message,null,null);
    }

    public static ResultData ok(Object data){
        return new ResultData(ErrorCode.SERVER_OK.getCode(),ErrorCode.SERVER_OK.getMessage(),data,null);
    }

    public static ResultData ok(Object data,Long count){
        return new ResultData(ErrorCode.SERVER_OK.getCode(),ErrorCode.SERVER_OK.getMessage(),data,count);
    }

    public static ResultData ok(Integer code,String message,Object data,Long count){
        return new ResultData(code,message,data,count);
    }

    public static ResultData failure(){
        return new ResultData(ErrorCode.SERVER_SYSTEM_ERROR.getCode(),ErrorCode.SERVER_SYSTEM_ERROR.getMessage(),null,null);
    }

    public static ResultData failure(Integer code,String message){
        return new ResultData(code,message,null,null);
    }

    public static ResultData failure(ErrorCode errorCode){
        return new ResultData(errorCode.getCode(),errorCode.getMessage(),null,null);
    }
}
